package display;

import java.util.Hashtable;


import database.RecordSearch;
import dbmanager.Column;
import dbmanager.DBManager;
import dbmanager.GetIdName;


public class Field implements Display
{
	String path;
	DBManager Db;
	//SearchRecord Sr;
	RecordSearch ps;
	GetIdName gid ;
	String id;
	public  Hashtable<Object,Object> Result = new Hashtable<Object,Object>();
	
	public void setId(String id,DBManager Db)
	{
		 this.id = id; 
		 this.Db = Db;
		 //path = Input.MASTERREPORTSPATH.concat(id+"//"+id+"_mid"+Input.FILRFORMAT);
		 /*Sr = new SearchRecord(path);
		 Sr.fileOpen();*/
		 ps = new RecordSearch(Db);
		 gid = new GetIdName(Db);	
  }
	
	public Hashtable<Object,Object> getObject()
	 {  
		Hashtable<Object,Object> map = new 	 Hashtable<Object,Object>();	
		map.put("mid", id);
		map.put("td", "null");
	 	try {
	 			System.out.println(map);
				/*String line[] = Sr.getRecordSet(map);
				Sr.fileClose();*/
				ps.setConditionMap(map);
				String line[] = ps.getArrayFromResultSet();
				
				int index_pid =  Column.pid_index-1;
				int index_vt =   Column.vt_index-1;
				int index_pv =   Column.pv_index-1;
				
				for(int i=0;i<line.length;i++)
					{
					System.out.println("The main o/p line ="+line[i] + "Path is " +path);
						String SubString[] = line[i].split("\t");
						if(SubString[index_pid].equals("9")) 
							continue;
						
						String value="";
					    if(SubString[index_pv].equals("0"))
						    	 value= SubString[index_vt].toLowerCase();
					    else
					    	value= gid.getItem(SubString[index_pv]);
						Result.put(gid.getItem(SubString[index_pid]).toLowerCase(),value);
						//System.out.println("The main o/p   pid= "+index_pid);
					}
				System.out.println("the Display property map is " + Result);	
		    return Result;
			} catch (Exception e) {
				e.printStackTrace();
			}
			return Result;
		}
	public void initializeData() 
	{
		
	}
	 
	 
	public static void main(String[] args) {
			//Field ds =new Field("C://Reports//Basic_Reports//Master_Reports//79//79_mid.txt");
		DBManager db = new DBManager();
		db.getConnect();
		Field ds =new Field();
	//	ds.setId("107",db);
		ds.setId("109",db);
			@SuppressWarnings("unused")
			Hashtable<Object,Object> map = new Hashtable<Object,Object>();
		//	map.put("mid", "107");
		 	System.out.println(ds.getObject());
			}

}